
package com.itheima.crm.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itheima.common.utils.Page;
import com.itheima.crm.mapper.ApplicationDao;
import com.itheima.crm.pojo.Application;
import com.itheima.crm.service.ApplicationService;



/**
 * 客户管理
 * 
 * @author lx
 *
 */
@Service
public class ApplicationServiceImpl implements ApplicationService {

	@Autowired
	private ApplicationDao applicationdao;

	@Override
	public Application selectApplicationById(Integer id) {
		// TODO Auto-generated method stub
		return applicationdao.selectApplicationById(id);
	}

	@Override
	public void updateApproveById(Application application) {
		applicationdao.updateApproveById(application);

	}
	@Override
	public void updateApplicationById(Application application) {
		// TODO Auto-generated method stub
		applicationdao.updateApplicationById(application);
	}

	@Override
	public void insertApplication(Application application) {
		applicationdao.insertApplication(application);

	}

	@Override
	public void deleteApplication(Integer id) {
		applicationdao.deleteApplication(id);

	}

	@Override
	public Page<Application> selectApplicationList(Application vo) {
		Page<Application> page = new Page<Application>();
		// 每页数
		page.setSize(5);
		vo.setSize(5);
		if (null != vo) {
			// 判断当前页
			if (null != vo.getPage()) {
				page.setPage(vo.getPage());
				vo.setStartRow((vo.getPage() - 1) * vo.getSize());
			}

			// 总条数
			page.setTotal(applicationdao.ApplicationCount(vo));
			System.out.println("业务查看分页"+applicationdao.ApplicationCount(vo));
			page.setRows(applicationdao.selectApplicationList(vo));
		}
		return page;

	}

	@Override
	public Page<Application> selectMyApplication(Application vo) {
		Page<Application> page = new Page<Application>();
		// 每页数
		page.setSize(5);
		vo.setSize(5);
		if (null != vo) {
			// 判断当前页
			if (null != vo.getPage()) {
				page.setPage(vo.getPage());
				vo.setStartRow((vo.getPage() - 1) * vo.getSize());
			}

			// 总条数
			page.setTotal(applicationdao.myApplicationCount(vo));
			page.setRows(applicationdao.selectMyApplication(vo));
		}
		return page;

	}

	@Override
	public Integer selectYGidBylogin(String loginname, String loginpw) {

		return applicationdao.selectYGidBylogin(loginname, loginpw);
	}

	@Override
	public Page<Application> selectOrganizationApplication(Application vo) {
		Page<Application> page = new Page<Application>();
		// 每页数
		page.setSize(5);
		vo.setSize(5);
		if (null != vo) {
			// 判断当前页
			if (null != vo.getPage()) {
				page.setPage(vo.getPage());
				vo.setStartRow((vo.getPage() - 1) * vo.getSize());
			}

			// 总条数
			System.out.println(applicationdao.OrganizationApplicationCount(vo));
			page.setTotal(applicationdao.OrganizationApplicationCount(vo));
			page.setRows(applicationdao.selectOrganizationApplication(vo));
			
		}
		return page;

	}

	@Override
	public Page<Application> selectMyAndOrganization(Application vo) {
		Page<Application> page = new Page<Application>();
		
		// 每页数
				page.setSize(5);
				vo.setSize(5);
				if (null != vo) {
					// 判断当前页
					if (null != vo.getPage()) {
						page.setPage(vo.getPage());
						vo.setStartRow((vo.getPage() - 1) * vo.getSize());
					}

			// 总条数
			
		
			page.setTotal(applicationdao.selectMyAndOrganizationCount(vo));
			page.setRows(applicationdao.selectMyAndOrganization(vo));
		}
		return page;
	}

	@Override
	public Page<Application> selectHuiYi(Application vo) {

			Page<Application> page = new Page<Application>();
			
			// 每页数
					page.setSize(5);
					vo.setSize(5);
					if (null != vo) {
						// 判断当前页
						if (null != vo.getPage()) {
							page.setPage(vo.getPage());
							vo.setStartRow((vo.getPage() - 1) * vo.getSize());
						}

				// 总条数
				
			
				page.setTotal(applicationdao.ApplicationCountHuiYi(vo));
				page.setRows(applicationdao.selectHuiYi(vo));
			}
			return page;
	
	}

	@Override
	public void updateApplicationResult(Integer id) {
		applicationdao.updateApplicationResult(id);
		
	}

	@Override
	public Integer MaxApplicationId() {
		// TODO Auto-generated method stub
		return applicationdao.CountMaxId();
	}

	

	

}
